package com.situ.day1;

import org.junit.Test;

import java.util.Arrays;

public class Hello {
    //main   arg: argument 参数
    public static void main(String[] args) {
        //sout
        System.out.println();
        //soutm
        System.out.println("Hello.main");
    }

    //junit:单元测试
    //Alt+Enter
    @Test
    public void test1() {
        System.out.println("Hello.test1");
        int i = 1;
        i++;//单独使用 i=2
        System.out.println(i++);//2
        System.out.println(i);//3

        //短路
        int num1 = 3;
        int num2 = 5;
        //&&短路
        if (num1 < 0) {
            num1++;
        }
        System.out.println(false);//false
        System.out.println(num1);//3
        System.out.println(num2);//5

        //||短路
        System.out.println(num1 > 0 || num1++ < num2);//true
        System.out.println(num1);//3
        System.out.println(num2);//5
    }

    @Test
    public void test2() {
//        ****
//        ****
//        ****
        for (int i = 1; i <= 4; i++) {
            System.out.print("*");
        }
        System.out.println();
        for (int i = 1; i <= 3; i++) {
            System.out.println("*");
        }
        System.out.println("------------");
        for (int i = 1; i <= 3; i++) {
            //i=1 打印第一行
            //i=2 打印第二行
            for (int j = 1; j <= 4; j++) {
                System.out.print("*");
            }
            //打印完一行之后需要换行
            System.out.println();
        }
    }

//    *
//    **
//    ***
//    ****
//    *****
    @Test
    public void tes34() {
        //i=1  j=1
        //i=2  j=2
        //i=3  j=3
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                //System.out.print("2*6=12\t");
                System.out.print(j+"*"+i+"="+(i*j)+"\t");
            }
            System.out.println("");
        }
    }

    @Test
    public void test45() {
        int[] array = new int[4];
        array[0] = 33;
        array[1] = 2;
        array[2] = 45;
        array[3] = 19;
        //java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4
        for (int i = 0; i <= array.length; i++) {
            System.out.println(array[i]);
        }
    }

    @Test
    public void test55() {
        int[] array = {40, 17, 21, 1};
        //i=1  j=3
        //i=2  j=2
        //i=3  j=1
        //i+j=array.length  j=array.length-i
        for (int i = 1; i <= array.length - 1; i++) {
            for (int j = 0; j < array.length - i; j++) {
                if (array[j] > array[j + 1]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }

        //Arrays是数组操作的工具类
        System.out.println(Arrays.toString(array));
        /*for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }*/
    }


}
